//
//  BHCommonBannerImageCell.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/7/27.
//

import UIKit

class BHCommonBannerImageCell: UICollectionViewCell {
    lazy var backImage: UIImageView = {
        let view = UIImageView.init()
        view.backgroundColor = .clear
        view.contentMode = .scaleAspectFill
        return view
    }()
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    var cellImageHaveCorner: Bool = false {
        didSet {
            if cellImageHaveCorner == false {
                if self.backImage.haveRaiuds == false {
                    self.backImage.addLayerCorner(0, 0, .white)
                    self.backImage.haveRaiuds = true
                }
            }else {
                if self.backImage.haveRaiuds == false {
                    self.backImage.addLayerCorner(10, 0, .white)
                    self.backImage.haveRaiuds = true
                }
            }
        }
    }
    
    
    var bannerImageUrl: String = "" {
        willSet {}
        didSet {
            self.backImage.sd_setImage(with: URL(string: bannerImageUrl), placeholderImage: nil, options: .retryFailed, completed: nil)
            
        }
    }
    
    func configImage(bannerUrl imgPath: String, placeHolder placeImage: UIImage) {
        self.backImage.sd_setImage(with: URL(string: imgPath), placeholderImage: placeImage, options: .retryFailed, completed: nil)
      
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.addSubview(self.backImage)
        
        self.backImage.mas_makeConstraints { (make) in
            make?.left.right()?.bottom()?.top()?.equalTo()(self)
        }
        
        self.clipsToBounds = true
        
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
    }
}
